package com.mccken.practice.top100.Top_1$20.Top_13;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-01-02 18:04
 **/
public class Temp_13 {

	// 使用额外数组，时间复杂度O(n),空间复杂度O(1)
	public static void main(String[] args) {
		rotate1();
	}

	private static void rotate2() {
		int[] a = {0, 1, 2, 3, 4, 5, 6, 7};
		int len = a.length;
		// 右移k为
		int k = 3;
		k = k % len;

	}


	private static void rotate1() {
		int[] a = { 1, 2, 3, 4, 5, 6, 7};
		int len = a.length;
		// 右移k为
		int k = 3;
		k = k % len;
//
//		int[] new_arr = new int[len];
//
//		for (int i = 0; i < len; i++) {
//			new_arr[(len + i + k) % len] = a[i];
//		}
//		a[0] = temp;
//		System.out.println(Arrays.toString(new_arr));

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < len; i++) {
			list.add(a[i]);	
		}

		Collections.rotate(list, 3);
		for (int i = 0; i < len; i++) {
			a[i] = list.get(i);	
		}
		System.out.println(list);
		System.out.println(Arrays.toString(Arrays.stream(a).toArray()));
	}
}
